package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags="护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> listAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.getAllNursingLevel();
        return success(nursingLevelVos);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加护理等级")
        public ResponseResult insertNursingLevel(@RequestBody NursingLevelVo nursingLevelVo) {
        nursingLevelService.insertNursingLevel(nursingLevelVo);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级")
    public ResponseResult<List<NursingLevelVo>> listByPage( @ApiParam(value = "护理等级名称")
                                                                @RequestParam(value = "name", required = false) String name,
                                                            @ApiParam(value = "状态：0-禁用，1-启用")
                                                                @RequestParam(value = "status", required = false) Integer status,
                                                            @ApiParam(value = "当前页码")
                                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                            @ApiParam(value = "每页显示数量")
                                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingLevelVo> nursingLevelPageInfo = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingLevelPageInfo);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getNursingLevelById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getNursingLevelById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult updateNursingLevel(@RequestBody  NursingLevelVo nursingLevelVo) {
        nursingLevelService.updateNursingLevel(nursingLevelVo);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable Long id) {
        nursingLevelService.deleteNursingLevel(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "根据id修改护理等级状态")
    public ResponseResult modifyNursingLevelStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.updateNursingLevelStatus(id, status);
        return success();
    }


}
